using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The StudentAttendanceTypeManager class is responsible for managing BO.StudentAttendanceType objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class StudentAttendanceTypeManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all StudentAttendanceType objects in the database.
        /// </summary>
        /// <returns>A list with all StudentAttendanceType from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static StudentAttendanceTypeList GetList()
        {
            return StudentAttendanceTypeDB.GetList();
        }

        /// <summary>
        /// Gets a single StudentAttendanceType from the database without its data.
        /// </summary>
        /// <param name="attendanceTypeCode">The AttendanceTypeCode of the StudentAttendanceType in the database.</param>
        /// <returns>A StudentAttendanceType object when the AttendanceTypeCode exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAttendanceType GetItem(short attendanceTypeCode)
        {
            return GetItem(attendanceTypeCode, false);
        }

        /// <summary>
        /// Gets a single StudentAttendanceType from the database.
        /// </summary>
        /// <param name="attendanceTypeCode">The AttendanceTypeCode of the StudentAttendanceType in the database.</param>
        /// <param name="getStudentAttendanceTypeRecords">Determines whether to load all associated StudentAttendanceType records as well.</param>
        /// <returns>
        /// A StudentAttendanceType object when the AttendanceTypeCode exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAttendanceType GetItem(short attendanceTypeCode, bool getStudentAttendanceTypeRecords)
        {
            StudentAttendanceType myStudentAttendanceType = StudentAttendanceTypeDB.GetItem(attendanceTypeCode);
            return myStudentAttendanceType;
        }

        /// <summary>
        /// Saves a StudentAttendanceType in the database.
        /// </summary>
        /// <param name="myStudentAttendanceType">The StudentAttendanceType instance to save.</param>
        /// <returns>The new AttendanceTypeCode if the StudentAttendanceType is new in the database or the existing AttendanceTypeCode when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static short Save(StudentAttendanceType myStudentAttendanceType)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                short studentAttendanceTypeAttendanceTypeCode = Convert.ToInt16(StudentAttendanceTypeDB.Save(myStudentAttendanceType));

                //  Assign the StudentAttendanceType its new (or existing AttendanceTypeCode).
                myStudentAttendanceType.AttendanceTypeCode = studentAttendanceTypeAttendanceTypeCode;

                myTransactionScope.Complete();

                return studentAttendanceTypeAttendanceTypeCode;
            }
        }

        /// <summary>
        /// Deletes a StudentAttendanceType from the database.
        /// </summary>
        /// <param name="myStudentAttendanceType">The StudentAttendanceType instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(StudentAttendanceType myStudentAttendanceType)
        {
            return StudentAttendanceTypeDB.Delete(myStudentAttendanceType.AttendanceTypeCode);
        }

        #endregion

    }

}
